//
//  ChangePwdByPhoneController.m
//  DYLYJ
//
//  Created by JM on 15/11/23.
//  Copyright © 2015年 JM. All rights reserved.
//

#import "ChangePwdByPhoneController.h"
#import "RegisterSecurityCodeVC2.h"
#import "DYUIKit.h"
#import "NSString-Helper.h"
#import "DYRequestAll.h"
@interface ChangePwdByPhoneController ()
@property(nonatomic,strong)IBOutlet UITextField *phoneTextFeild;
@end

@implementation ChangePwdByPhoneController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (IBAction)clickNext:(id)sender {
    [self.view endEditing:YES];
    
    if (![NSString isValidateEmail:self.phoneTextFeild.text]  &&  (![NSString isPhoneNumber:self.phoneTextFeild.text])){
        [MJAlertView showMessage:@"邮箱格式错误或手机号非法"];
        return;
    }else if ([NSString isValidateEmail:self.phoneTextFeild.text]){
        ChangePwdByEmailRequest *request  = [ChangePwdByEmailRequest request];
        request.DY_email = self.phoneTextFeild.text;
        [request requstWithCompletionHandler:^(DYResponse *rs, NSError *error) {
            if (error) {
                [MJAlertView showMessage:error.localizedDescription];
                return ;
            }
            [MJAlertView showAlertViewWithTitle:@"提示" message:@"已经发送邮件至邮箱请查看" clickedButtonBlock:^(NSInteger index) {
                [self.navigationController popViewControllerAnimated:YES];
            } cancelButtonTitle:@"确定" otherButtonTitles:nil];
        }];
    }else if ([NSString isPhoneNumber:self.phoneTextFeild.text]) {//手机
        UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
        RegisterSecurityCodeVC2* vc = [storyboard instantiateViewControllerWithIdentifier:@"RegisterSecurityCodeVC2"];
        vc.name = self.phoneTextFeild.text;
        vc.pwd = self.phoneTextFeild.text;
        [self.navigationController pushViewController:vc animated:YES];
    }
}

@end
